package com.jiazhong.equals;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Comparator;
import java.util.Date;
import java.util.TreeSet;

public class Test3 {
    public static void main(String[] args) throws ParseException {
//        TreeSet<User> set=new TreeSet<>();//使用user对象中的默认排序规则进行排序
//        TreeSet<User> set=new TreeSet<>(new User.sortByScoreDESC());
        TreeSet<User> set=new TreeSet<>(new Comparator<User>() {//使用匿名内部类实现比较器接口
            @Override
            public int compare(User o1, User o2) {
                return o1.getRegDate().compareTo(o2.getRegDate());
            }
        });
        User user=new User(1,"admin1",100,new Date());
        User user1=new User(2,"admin2",80,new SimpleDateFormat("yyyy-MM-dd").parse("2020-12-10"));
        User user2=new User(3,"admin3",290,new SimpleDateFormat("yyyy-MM-dd").parse("2018-10-12"));
        User user3=new User(4,"admin4",300,new SimpleDateFormat("yyyy-MM-dd").parse("2019-6-10"));
        set.add(user);
        set.add(user1);
        set.add(user2);
        set.add(user3);
        for (User u :set) {
            System.out.println(u);
        }
    }
}
